namespace NFreeMarker.Core
{
    internal sealed class OrExpression : BooleanExpression
    {
        private readonly Expression _left;
        private readonly Expression _right;

        internal OrExpression(Expression left, Expression right)
        {
            _left = left;
            _right = right;
        }

        internal override bool IsTrue(Environment env)
        {
            return _left.IsTrue(env) || _right.IsTrue(env);
        }

        public override string GetCanonicalForm()
        {
            return _left.GetCanonicalForm() + " || " + _right.GetCanonicalForm();
        }

        internal override bool IsLiteral()
        {
            return ConstantValue != null || (_left.IsLiteral() && _right.IsLiteral());
        }

        protected override Expression DeepCloneImpl(string name, Expression subst)
        {
            return new OrExpression(_left.DeepClone(name, subst), _right.DeepClone(name, subst));
        }
    }
}